package edu.mbb.core;

import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
 * mybatis 配置类
 * 
 * @author mbb
 *
 */
public class Configuration {
	/**
	 * 接口和xml对应的关系表
	 */
	private static final Map<String, Object> mapperInFaceToXml = Maps.newHashMap();

	/**
	 * xml id中对应的sql
	 */
	private static final Map<String, Object> xmlToInFaceMethodSql = Maps.newHashMap();
	/**
	 * xml中的参数列表 为以后注解准备
	 */
	private static final Map<String, List<String>> xmlArgs = Maps.newConcurrentMap();

	/**
	 * 注解中的值和xml中的值做对应
	 */
	private static final Map<String, Object> argsValues = Maps.newConcurrentMap();

	/**
	 * 得到xml和接口的映射关系
	 * 
	 * @return
	 */
	public static Map<String, Object> getmapperInFaceToXml() {
		return mapperInFaceToXml;
	}

	/**
	 * 使接口和xml进行映射
	 * 
	 * @param interFaceName
	 *            接口的名字
	 * @param obj
	 *            xml对象
	 */
	public static void insertMapperInFaceToXml(String interFaceName, Object obj) {
		mapperInFaceToXml.put(interFaceName, obj);
	}

	/**
	 * 通过接口名字得到 xml对象
	 * 
	 * @param interFaceName
	 * @return
	 */
	public static Object getXmlByInfaceName(String interFaceName) {
		return mapperInFaceToXml.get(interFaceName);
	}

	/**
	 * 得到xml和接口的映射关系
	 * 
	 * @return
	 */
	public static Map<String, Object> getXmlToInFaceMethodSql() {
		return xmlToInFaceMethodSql;
	}

	/**
	 * 使接口和xml进行映射
	 * 
	 * @param interFaceName
	 *            接口的名字
	 * @param obj
	 *            xml对象
	 */
	public static void insertXmlToInFaceMethodSql(String interFaceName, Object obj) {
		xmlToInFaceMethodSql.put(interFaceName, obj);
	}

	/**
	 * 通过接口名字得到 xml对象
	 * 
	 * @param interFaceName
	 * @return
	 */
	public static Object getXmlToInFaceMethodSql(String interFaceName) {
		return xmlToInFaceMethodSql.get(interFaceName);
	}

	public static Map<String, List<String>> getXmlArgs() {
		return xmlArgs;
	}

	public static void insertXmlArgs(String interFaceName, List<String> obj) {
		xmlArgs.put(interFaceName, obj);
	}

	public static List<String> getXmlArgs(String key) {
		List<String> list = xmlArgs.get(key);
		if (list == null) {
			list = Lists.newArrayList();
			xmlArgs.put(key, list);
		}
		return list;
	}

	public static Map<String, Object> getArgsValues() {
		return argsValues;
	}

	public static void insertArgsValues(String interFaceName, Object obj) {
		argsValues.put(interFaceName, obj);
	}

	public static Object getArgsValues(String key) {
		return argsValues.get(key);
	}

	public static void cleanData() {
		argsValues.clear();
		xmlArgs.clear();
	}

}
